#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdkhooks>

#define PLUGIN_VERSION "1.0"

ConVar C_WitchDamage;

float F_WitchDamage;

public Plugin myinfo =
{
	name = "l4d2_WitchDamageModify",
	author = "X光",
	description = "女巫伤害修改",
	version = PLUGIN_VERSION,
	url = "QQ群59046067"
};

#define CVAR_FLAGS			FCVAR_NOTIFY

public void OnPluginStart()
{
	CreateConVar("l4d2_witch_damage_modify_version", PLUGIN_VERSION, "插件版本", FCVAR_NOTIFY);

	C_WitchDamage = CreateConVar("l4d2_witch_damage_modify", "50.0", "女巫的伤害值", CVAR_FLAGS);
	C_WitchDamage.AddChangeHook(convar_changed);

	//AutoExecConfig(true, "l4d2_WitchDamageModify");
}

void convar_changed(ConVar convar, const char[] oldValue, const char[] newValue)
{
	get_cvars();
}

void get_cvars()
{
	F_WitchDamage = C_WitchDamage.FloatValue;
}

public void OnConfigsExecuted()
{
	get_cvars();
}

bool IsValidClient(int client)
{
	return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2;
}

public void OnClientPutInServer(int client)
{
	SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom)
{
	if (IsValidEntity(attacker))
	{
		static char classname[32];
		GetEntityClassname(attacker, classname, sizeof classname);
		if (StrEqual(classname, "witch", false))
		{
			if (IsValidClient(victim))
			{
				damage = F_WitchDamage;
				return Plugin_Changed;
			}
		}
	}
	return Plugin_Continue;
}